<template>
  <div>
  <el-divider style="margin: 0rem;" content-position="left"><h3 style="font-size: 1.15rem;">教师管理</h3></el-divider>
  <my-table listPath="teacher/page" savePath="teacher/save" deletePath="teacher/delete" @crrent-Row="currrow"   @ :table="table" :pageParams="pageParams" :rules="rules" dialogTitle="对话框" :pageSize="[5,10,20,35,50]" :dialogForm="form" >
    <template v-slot:dialogSlot>
      <el-form-item label="用户名" prop="username">
          <el-input v-model="form.username" clearable></el-input>
      </el-form-item>
      <el-form-item label="教师姓名" prop="name">
          <el-input v-model="form.name" clearable></el-input>
      </el-form-item>
    </template>
    <template v-slot:mybutton>
         <el-button type="primary" @click="reset()" icon="el-icon-refresh" plain :disabled="!currRow"  size="small">重置密码</el-button>
    </template>
  </my-table>
  </div>
</template>

<script>
  import myTable from '../../components/myTable.vue';
  export default{
    name:'course',
    components:{myTable},
    data() {
      return {
       currRow:null,
       pageParams:{
            limit:10,
            page:1,
            sort:'id',
            order:'asc',
            search:''
        }
        ,
        form:{
          username:'',
          name:'',
        },
        table:[
          {
            title:'用户名',
            field:'username'
          },
          {
            title:'教师姓名',
            field:'name'
          }
        ],
        rules:{
          username: [{ required: true, message: '请输入用户名', trigger: 'change' }],
          name: [{ required: true, message: '请输入教师姓名', trigger: 'change' },
                 {required: true,pattern: /^[\u4e00-\u9fa5_a-zA-Z0-9.·-]+$/,message: '姓名不支持特殊字符',trigger: 'change'}],
        },
      }
    },
    methods:{
      currrow(row){
        this.currRow=row;
      },
      reset(){
                 this.$confirm('是否重置此条数据密码', '提示', {
                       confirmButtonText: '确定',
                       cancelButtonText: '取消',
                       type: 'info'
                     }).then(() => {
                       this.$ajax.post('teacher/reset',this.currRow).then(res=>{
                         var result=res.data;
                         if(result.success){
                          this.$notify({
                            title: '提示',
                            message: '密码重置成功',
                            type: 'success',
                            position: 'bottom-right'
                          });
                         }
                       }).catch(err=>{
                         this.$message({
                           type: 'error',
                           message: '重置失败'
                         });
                       })
                     }).catch(() => {
                       this.$message({
                         type: 'info',
                         message: '已取消重置密码'
                       });
                     });

      }
    },
		created() {
			var role =window.sessionStorage.getItem("role")
				if(role!=='ROLE_ADMIN'){
					this.$router.back();
			}
		}
  }
</script>

<style>
</style>
